package com.neuqsoft.rd.citizen.thirdapp.sdk;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.neuqsoft.api.client.DefaultNeuqClient;
import com.neuqsoft.api.exception.NeuqApiException;
import com.neuqsoft.rd.citizen.thirdapp.sdk.dto.ActiveCardDTO;
import com.neuqsoft.rd.citizen.thirdapp.sdk.dto.CodeUsageDTO;
import com.neuqsoft.rd.citizen.thirdapp.sdk.dto.MsgUsageDTO;
import com.neuqsoft.rd.citizen.thirdapp.sdk.dto.PayUsageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author baidh
 * @date 2020/12/02
 */
@Service
public class DataService {

    @Autowired
    DefaultNeuqClient client;

    /**
     * 消息推送
     *
     * @return
     */
    public void msgStream(String uid) {
        Map<String, String> data = new HashMap<>(3);
        data.put("keyword1", "XXX景点");
        data.put("keyword2", "成人票");
        data.put("keyword3", DateUtil.today());

        MsgUsageDTO req = new MsgUsageDTO();
        req.setUid(uid);
//        req.setIdcard();
        req.setTemplateId("TEST");
        req.setData(data);
        req.setOccurTime(DateTime.now().toString(DatePattern.PURE_DATETIME_FORMAT));
        req.setMemo("购票成功");
        req.setGeoLongitude("39.942531");
        req.setGeoLatitude("119.586579");
        client.postJson("https://service.neuqsoft.com/ggfw/citizen/gateway/openapi/api/v1/open/stream/data/msg", null, req, "", Void.class);
    }

    /**
     * 解码信息回流
     *
     * @param uid
     * @param authCode
     * @return
     */
    public String codeStream(String uid, String authCode) throws NeuqApiException {
        CodeUsageDTO req = new CodeUsageDTO();
        req.setUid(uid);
//        req.setIdcard("715752711849419213");
        req.setAuthCode(authCode);
        req.setMethod("02");
        req.setOccurTime(DateTime.now().toString(DatePattern.PURE_DATETIME_FORMAT));
        req.setMemo("扫码乘车");
        req.setGeoLongitude("39.942531");
        req.setGeoLatitude("119.586579");
        return client.postJson("https://service.neuqsoft.com/ggfw/citizen/gateway/openapi/api/v1/open/stream/data/code", null, req, "", String.class);
    }

    /**
     * 支付信息回流
     *
     * @param uid
     * @param authCode
     * @return
     */
    public String payStream(String uid, String authCode) throws NeuqApiException {
        PayUsageDTO req = new PayUsageDTO();
        req.setUid(uid);
//        req.setIdcard("715752711849419213");
        req.setChannelCode("101");
        req.setOrderId("test" + DateTime.now().toString(DatePattern.PURE_DATETIME_FORMAT));
        req.setMoneyChange(100);
        req.setMoneyFlow("02");
        req.setOccurTime(DateTime.now().toString(DatePattern.PURE_DATETIME_FORMAT));
        req.setMemo("扫码乘车");
        req.setGeoLongitude("39.942531");
        req.setGeoLatitude("119.586579");
        return client.postJson("https://service.neuqsoft.com/ggfw/citizen/gateway/openapi/api/v1/open/stream/data/pay", null, req, "", String.class);
    }

    /**
     * 特种卡信息回流
     *
     * @param uid
     * @param authCode
     * @return
     */
    public String cardStream(String uid, String authCode) throws NeuqApiException {
        ActiveCardDTO req = new ActiveCardDTO();
        req.setUid(uid);
//        req.setIdcard("715752711849419213");
        req.setCardTypeId("TEST0CARD01");
        req.setSerialNumber("80000001");
        req.setCardAttach("");
        req.setActiveDate("20200101");
        req.setExpireDate("20991231");
        req.setState("01");
        return client.postJson("https://service.neuqsoft.com/ggfw/citizen/gateway/openapi/api/v1/open/stream/data/card", null, req, "", String.class);
    }

}
